﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.templates;
using l1cs.server.datatables;
using l1cs.server.serverpackets;

namespace l1cs.server.model.Instance
{
    public class L1DwarfInstance : L1NpcInstance
    {
        private static Logger _log = Logger.getLogger( typeof( L1DwarfInstance ).FullName );

        //private List<> _tpLocs;

        private int _tpId;

        /**
         * @param template
         */
        public L1DwarfInstance( L1Npc template ) : base( template ) { }

        override public void onAction( L1PcInstance pc )
        {
            L1Attack attack = new L1Attack( pc, this );
            attack.calcHit();
            attack.action();
        }

        override public void onTalkAction( L1PcInstance pc )
        {
            int objid = getId();
            L1NpcTalkData talking = NPCTalkDataTable.getInstance().getTemplate(
                    getNpcTemplate().get_npcId() );
            int npcId = getNpcTemplate().get_npcId();
            String htmlid = null;

            if ( talking != null )
            {
                if ( npcId == 60028 )
                { // エル
                    if ( !pc.isElf() )
                    {
                        htmlid = "elCE1";
                    }
                }

                if ( htmlid != null )
                { // htmlidが指定されている場合
                    pc.sendPackets( new S_NPCTalkReturn( objid, htmlid ) );
                }
                else
                {
                    if ( pc.getLevel() < 5 )
                    {
                        pc.sendPackets( new S_NPCTalkReturn( talking, objid, 2 ) );
                    }
                    else
                    {
                        pc.sendPackets( new S_NPCTalkReturn( talking, objid, 1 ) );
                    }
                }
            }
        }

        private int getTemplateid()
        {
            // Auto-generated method stub
            return 0;
        }

        override public void onFinalAction( L1PcInstance pc, String Action )
        {
            int objid = getTemplateid();
            if ( string.Compare( Action, "retrieve", true ) == 0 )
            {
                _log.finest( "Retrive items in storage" );
            }
            else if ( string.Compare( Action, "retrieve-pledge", true ) == 0 )
            {
                _log.finest( "Retrive items in pledge storage" );

                if ( string.Compare( pc.getClanname(), " ", true ) == 0 )
                {
                    _log.finest( "pc isnt in a pledge" );
                    S_ServerMessage talk = new S_ServerMessage( ( S_ServerMessage.NO_PLEDGE ), Action );
                    pc.sendPackets( talk );
                }
                else
                {
                    _log.finest( "pc is in a pledge" );
                }
            }
        }
    }
}
